/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __ADT_FILE_H__
#define __ADT_FILE_H__

#include "AdtChunkFile.h"

namespace PQGame
{
	//http://www.madx.dk/wowdev/wiki/index.php?title=ADT
	//in memory database,what 
	//maybe we should build our in memory file system for more control and 
	class AdtFile
	{
	public:
		PQEngine::FileBase *_file;

		int version;//file version
		int header_pos;

		char** mtexs;
		int mtexCount;//how many texture this adt file use

		char** mmdxs;
		int mmdxCount;

		char** mwmos;//world map object names
		int mwmoCount;//this is wmo count no repeat

		int mddfCount;
		adt_mddf *mddfs;

		int modfCount;//this is wmo(world map object) instance count
		adt_modf *modfs;

		adt_mhdr mhdr;

		//map chunck info
		adt_mcin mcins[16*16];
		AdtChunkFile *chunks[16*16];

	public:
		~AdtFile(void);

		inline MapChunkHeader *getChunkHeader(int index)
		{
			return chunks[index]->header;
		}

		inline int getChunkLayerCount(int index)
		{
			return chunks[index]->layerCount;
		}

		inline map_chunk_layer *getChunkLayerInfo(int chunkIndex,int layerIndex)
		{
			return chunks[chunkIndex]->layersInfo+layerIndex;
		}

		inline float *getChunkVerticesHeight(int index)
		{
			return chunks[index]->heights;
		}

		inline map_chunk_normal* getChunkNormals(int index)
		{
			return chunks[index]->normals;
		}

		AdtFile(PQEngine::FileBase* f);
	private:
		void init(PQEngine::FileBase *f);
		
		void initMHDR(PQEngine::FileBase *f);
		void initMCIN(PQEngine::FileBase *f);
		void initMTEX(PQEngine::FileBase *f);
		void initMMDX(PQEngine::FileBase *f);
		void initMWMO(PQEngine::FileBase *f);
		void initMDDF(PQEngine::FileBase *f);
		void initMODF(PQEngine::FileBase *f);
	};
}
#endif
